home *** CD-ROM | disk | FTP | other *** search
- /******************************************************************************
- * $Id: SoXtGLRRenderArea.C,v 1.1 1996/03/05 00:22:03 dave Exp $
- *
- * Source File Name: SoXtGLRRenderArea.c++
- *
- * Copyright (c) 1991-96 Silicon Graphics, Inc.
- * SILICON GRAPHICS INC., Mountain View, California
- *
- * Permission to use, copy, modify, distribute, and sell this software and
- * its documentation for any purpose is hereby granted without fee, provided
- * that the name of Silicon Graphics may not be used in any advertising or
- * publicity relating to the software without the specific, prior written
- * permission of Silicon Graphics.
- *
- * The software is provided AS-IS and without WARRANTY of any kind,
- * express, implied or otherwise, including without limitation, any
- * warranty of merchantabilityl or fitness for a particular purpose.
- *
- * In no event shall Silicon Graphics be liable for any special, incidental,
- * indirect or consequential damages of any kind, or any damages whatsoever
- * resulting from loss of use, data or profits, whether or not advised of the
- * possibility of damage, and on any theory of liability, arising out of or in
- * connection with the use or performance of this software. Contractor is
- * SILICON GRAPHICS, INC., 2011 N. Shoreline blvd., Mountain View, CA. 94039
- *
- * Language: C++
- *
- * Description:
- *
- * Revision History:
- * 02/08/96 ROE Initial Coding.
- *
- *****************************************************************************/
- #include "SoXtGLRRenderArea.h"
- #include <iostream.h>
-
- GLint
- SoXtGLRRenderArea::fallbackAttributes[] = {GLR_RGBA, GLR_RED_SIZE, 1,
- GLR_GREEN_SIZE, 1, GLR_BLUE_SIZE,
- 1, GLR_DEPTH_SIZE, 16, 0};
-
-
- SoXtGLRRenderArea::SoXtGLRRenderArea(int attributes[],
- Widget parent,
- const char *name,
- SbBool buildInsideParent,
- SbBool getMouseInput,
- SbBool getKeyboardInput) :
- SoXtRenderArea(parent, name, buildInsideParent,
- getMouseInput, getKeyboardInput), canvas(NULL), session(NULL)
- {
- session = glrOpenSession(NULL);
- if (session == NULL) {
- cerr << "Couldn't get GLR session, check $GLR_SERVER. Using local rendering." << endl;
- return;
- }
- GLrCanvasType canvasType;
-
- canvasType = glrGetCanvasType(session, attributes);
- if (canvasType == NULL) {
- canvasType = glrGetCanvasType(session, fallbackAttributes);
- if (canvasType == NULL) {
- cerr << "Couldn't find usable canvas type." << endl;
- exit(1);
- }
- }
- canvas = glrCreateCanvas(canvasType, NULL);
- if (canvas == NULL) {
- cerr << "Couldn't get a canvas." << endl;
- exit(1);
- }
- glrEstablishRenderState(canvas);
- }
-
- void SoXtGLRRenderArea::render(SoXtGLRRenderArea::Quality quality)
- {
- if (quality == SoXtGLRRenderArea::HIGH && session) {
- renderRemote(); // Rendering to GLR server.
- }
- else {
- SoXtRenderArea::render(); // Rendering locally.
- }
- }
-
- void SoXtGLRRenderArea::renderRemote()
- {
- GLint status;
- GLint duration;
- SbVec2s size;
- GLubyte *image = NULL;
-
-
- // We need the size of the window.
- size = getSize();
- image = (GLubyte *) new GLubyte[size[0] * size[1] * 3]; // 4 of RGB mode.
- if (image == NULL) {
-
- }
-
- status = glrBeginRenderInterval(canvas, size[0], size[1], 500, 30000);
- cerr << "glrBeginRenderInterval = " << ((status) ? "yes" : "FAILED")
- << endl;
-
- glEnable(GL_DEPTH_TEST);
-
- // We want to invalidate the cache.
- getGLRenderAction()->invalidateState();
-
- actualRedraw();
-
- glPixelStorei(GL_PACK_ALIGNMENT, 1);
- glReadPixels(0, 0, size[0], size[1], GL_RGB, GL_UNSIGNED_BYTE, image);
-
- status = glrEndRenderInterval(canvas, &duration);
- cerr << "glrEndRenderInterval = " << ((status) ? "yes" : "FAILED") << endl;
- cerr << "duration = " << duration << endl;
-
- // Change context back to the local window.
- glXMakeCurrent(getDisplay(), getNormalWindow(), getNormalContext());
-
- glDrawBuffer(GL_BACK);
- glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
- glDrawPixels(size[0], size[1], GL_RGB, GL_UNSIGNED_BYTE, image);
-
- glFinish();
-
- glXSwapBuffers(getDisplay(), getNormalWindow());
-
- if (image)
- delete [] image;
- }
-
-